
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 2
 * @Author : WangRuoyu 
 * @Date : 2023/5/11 16:56
 */

#include "iostream"
#include "cstring"
#include "algorithm"

using namespace std;

int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int isLeap(int year) {
    if (year % 4 == 0 && year % 100 || year % 400 == 0) {
        return 1;
    }
    return 0;
}

int getDays(int year, int month) {
    if (year == 2) return months[month] + isLeap(year);
    return months[month];
}

int main() {
    int year;
    int n;
    cin >> year >> n;
    int m = 1;
    int d = 0;
    for (int i = 1; i <= n; ++i) {
        int days = getDays(year, m);
        if (d < days) {
            d++;
        } else {
            m++;
            d = 1;
        }
    }
    cout << m << endl << d;
    return 0;
}